#coding=utf-8
import os,sys
os.environ['DJANGO_SETTINGS_MODULE'] = 'ssr.settings'
from ssr.seq.models import SeqFasta, SsrRecord
from django.db.models import Max

def get_motifs(n):
  r = SsrRecord.objects.filter(len_motif=n).values('motif').distinct()
  return [i.values()[0] for i in r]
  
if __name__  == '__main__':
  for i in range(2, 10):
    print i
    motifs = get_motifs(i)
    for m in motifs:
      max_n = SsrRecord.objects.filter(motif=m).aggregate(Max('n'))['n__max']
      srs = SsrRecord.objects.filter(motif=m).filter(n=max_n).all()
      gis = [s.seq.gi for s in srs]
     
      print m, '\t', SsrRecord.objects.filter(motif=m).count(), '\t',  max_n, '\t', gis[0] #','.join(gis)

